//package com.hivision.controller.Energy;
//
//import com.hivision.alimqttapi.entity.TechnicalAttribute;
//import com.hivision.iot.api.AliReqClient;
//import com.hivision.iot.dto.AttributeValueRequestDTO;
//import com.hivision.mapper.TechnicalAttributeMapper;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.math.BigDecimal;
//import java.time.ZoneId;
//import java.time.ZonedDateTime;
//import java.time.format.DateTimeFormatter;
//import java.util.*;
//
//
//@RequestMapping("/Zlgycs")
//@RestController
//@Slf4j
//public class Zlgycs {
//
//    @Autowired
//    private AliReqClient reqClient;
//
//    @Autowired
//    TechnicalAttributeMapper technicalAttributeMapper;
//
//    private static final Map<String, String> informationMap = new HashMap<>();
//
//    List<String> list1 = Arrays.asList("P36_01TAR01_B40","P36_01TAR01_B401","P36_01RIT01_B402","P36_02TAR01_B40","P36_02TAR01_B401","P36_02RIT01_B402","P36_01FIL01_S331","P36_01FIL01_S332","P36_01FIL01_S333","P36_01FI_S334","P36_02FIL01_S331","P36_02FIL01_S332","P36_02FIL01_S333","P36_02FI_S334","P36_01VL01_S32F","P36_02VL01_S32F","P36_00VL01_S32F","P36_02VL02_S32F");
//
//    List<String> list2 = Arrays.asList("P36_02VL02_hycs1","P36_02VL02_hycs2","P36_02VL02_hycs3","P36_02VL02_hycs4","P36_02VL02_hycs5","P36_02VL02_hycs6","P36_02VL02_hycs7","P36_02VL02_hycs8","P36_02VL02_hycs9","P36_02VL02_hycs10","P36_02VL02_hycs11","P36_02VL02_hycs12","P36_02VL02_hycs13","P36_02VL02_hycs14","P36_02VL02_hycs15","P36_02VL02_hycs16","P36_02VL02_hycs17","P36_02VL02_hycs18","P36_02VL02_hycs19","P36_02VL02_hycs20","P36_02VL02_hycs21","P36_02VL02_hycs22","P36_02VL02_hycs23","P36_02VL02_hycs24","P36_02VL02_hycs25","P36_02VL02_hycs26","P36_02VL02_hycs27");
//
//    static {
//        informationMap.put("P36_02VL02_hycs1","13,9");
//        informationMap.put("P36_02VL02_hycs2","11,5");
//        informationMap.put("P36_02VL02_hycs3","13,9");
//        informationMap.put("P36_02VL02_hycs4","10,4");
//        informationMap.put("P36_02VL02_hycs5","13,9");
//        informationMap.put("P36_02VL02_hycs6","1.5,0");
//        informationMap.put("P36_02VL02_hycs7","10,8.5");
//        informationMap.put("P36_02VL02_hycs8","4,2");
//        informationMap.put("P36_02VL02_hycs9","1.2,0.8");
//        informationMap.put("P36_02VL02_hycs10","25,20");
//        informationMap.put("P36_02VL02_hycs11","0.5,0");
//        informationMap.put("P36_02VL02_hycs12","6,4");
//        informationMap.put("P36_02VL02_hycs13","4.5,4");
//        informationMap.put("P36_02VL02_hycs14","40,0");
//        informationMap.put("P36_02VL02_hycs15","5,0");
//        informationMap.put("P36_02VL02_hycs16","23,19");
//        informationMap.put("P36_02VL02_hycs17","6.6,5.6");
//        informationMap.put("P36_02VL02_hycs18","1900,1100");
//        informationMap.put("P36_02VL02_hycs19","20,15");
//        informationMap.put("P36_02VL02_hycs20","1000,400");
//        informationMap.put("P36_02VL02_hycs21","6.2,5");
//        informationMap.put("P36_02VL02_hycs22","6.2,5");
//        informationMap.put("P36_02VL02_hycs23","2,0");
//        informationMap.put("P36_02VL02_hycs24","6.2,5");
//        informationMap.put("P36_02VL02_hycs25","1,0");
//        informationMap.put("P36_02VL02_hycs26","200,0");
//        informationMap.put("P36_02VL02_hycs27","5,0");
//    }
//
//    @Scheduled(cron="0 */1 * * * ?")
//    @GetMapping("write")
//    public void writeValue(){
//        for (String s : list1) {
//            // 获取当前系统的日期时间，考虑到时区
//            ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
//            // 创建一个日期时间格式器，匹配所需的格式
//            DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
//            // 格式化当前日期时间为字符串
//            String formattedNow = now.format(formatter);
//
//            TechnicalAttribute technicalAttribute1=new TechnicalAttribute();
//            technicalAttribute1.setAttributeGroupName(s);
//            technicalAttribute1.setAttributeCode("gycs");
//            BigDecimal bigDecimal = technicalAttributeMapper.selectTechnicalAttributeList2(technicalAttribute1);
//
//            BigDecimal randomFloat = null;
//            if(bigDecimal == null){
//                randomFloat = getInitFloatNum(2,2);
//            }else{
//                randomFloat = bigDecimal.add(new BigDecimal("0.1"));
//            }
//
//            AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
//            attributeValueRequestDTO.setAssetCode(s);
//            attributeValueRequestDTO.setAttributeCode("gycs");
//            attributeValueRequestDTO.setValue(randomFloat.toPlainString());
//            reqClient.patchAttributeValue(attributeValueRequestDTO);
//
//            TechnicalAttribute technicalAttribute=new TechnicalAttribute();
//            technicalAttribute.setWritable("t");
//            technicalAttribute.setMeasureUni("无");
//            technicalAttribute.setMinValue("min无");
//            technicalAttribute.setMaxValueNew("max无");
//            technicalAttribute.setAssetCode(s);
//            technicalAttribute.setAttributeName("无");
//            technicalAttribute.setDataTypeNew("Double");
//            technicalAttribute.setAttributeGroupName(s);
//            technicalAttribute.setAttributeCode("gycs");
//            technicalAttribute.setAttributeDescs("无");
//            technicalAttribute.setAttributeGroupDescs("无");
//            technicalAttribute.setEnumValue(randomFloat.toPlainString());
//            technicalAttribute.setPrecisionNew(36L);
//            technicalAttribute.setCreatedAt(formattedNow);
//            technicalAttribute.setModifiedAt(formattedNow);
//            technicalAttributeMapper.insertTechnicalAttribute2(technicalAttribute);
//
//            log.info("值为:"+attributeValueRequestDTO);
//        }
//
//
//
//
//        for (String s : list2) {
//
//            // 获取当前系统的日期时间，考虑到时区
//            ZonedDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Shanghai"));
//            // 创建一个日期时间格式器，匹配所需的格式
//            DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME;
//            // 格式化当前日期时间为字符串
//            String formattedNow = now.format(formatter);
//
//            TechnicalAttribute technicalAttribute1=new TechnicalAttribute();
//            technicalAttribute1.setAttributeGroupName(s);
//            technicalAttribute1.setAttributeCode("hycs");
//            BigDecimal bigDecimal = technicalAttributeMapper.selectTechnicalAttributeList2(technicalAttribute1);
//
//
//            String value = informationMap.get(s);
//            String[] split = value.split(",");
//            BigDecimal max = new BigDecimal(split[0]);
//            BigDecimal min = new BigDecimal(split[1]);
//
//            BigDecimal randomFloat = null;
//            if(bigDecimal == null){
//                randomFloat = min;
//            }else{
//                randomFloat = bigDecimal.add(new BigDecimal("0.1"));
//                if(randomFloat.compareTo(max) > 0){
//                    randomFloat = min;
//                }
//            }
//
//            AttributeValueRequestDTO attributeValueRequestDTO = new AttributeValueRequestDTO();
//            attributeValueRequestDTO.setAssetCode(s);
//            attributeValueRequestDTO.setAttributeCode("hycs");
//            attributeValueRequestDTO.setValue(randomFloat.toPlainString());
//            reqClient.patchAttributeValue(attributeValueRequestDTO);
//
//            TechnicalAttribute technicalAttribute=new TechnicalAttribute();
//            technicalAttribute.setWritable("t");
//            technicalAttribute.setMeasureUni("无");
//            technicalAttribute.setMinValue("min无");
//            technicalAttribute.setMaxValueNew("max无");
//            technicalAttribute.setAssetCode(s);
//            technicalAttribute.setAttributeName("无");
//            technicalAttribute.setDataTypeNew("Double");
//            technicalAttribute.setAttributeGroupName(s);
//            technicalAttribute.setAttributeCode("hycs");
//            technicalAttribute.setAttributeDescs("无");
//            technicalAttribute.setAttributeGroupDescs("无");
//            technicalAttribute.setEnumValue(randomFloat.toPlainString());
//            technicalAttribute.setPrecisionNew(36L);
//            technicalAttribute.setCreatedAt(formattedNow);
//            technicalAttribute.setModifiedAt(formattedNow);
//            technicalAttributeMapper.insertTechnicalAttribute2(technicalAttribute);
//
//            log.info("值为:"+attributeValueRequestDTO);
//        }
//
//
//
//    }
//
//
//    private BigDecimal getInitFloatNum(int num1, int num2) {
//
//        StringBuilder builder = new StringBuilder();
//
//        // 创建Random类的实例
//        Random random = new Random();
//        // 设置随机数范围的最小值和最大值
//        int min = 0; // 最小值（包含）
//        int max = 9; // 最大值（包含）
//
//        for (int i = 0; i < num1; i++) {
//            // 获取指定范围内的随机数
//            int randomNumber = random.nextInt(max - min + 1) + min;
//            builder.append(randomNumber);
//        }
//
//        builder.append(".");
//
//        for (int i = 0; i < num2; i++) {
//            // 获取指定范围内的随机数
//            int randomNumber = random.nextInt(max - min + 1) + min;
//            builder.append(randomNumber);
//        }
//
//        return new BigDecimal(builder.toString());
//    }
//}
